Skip to content

[devel] feat: implement rolling pilot log output#155

Merged
fstagni merged 1 commit into
DIRACGrid:develfrom
marianne013:devel
Aug 23, 2022
Merged

[devel] feat: implement rolling pilot log output#155
fstagni merged 1 commit into
DIRACGrid:develfrom
marianne013:devel

Conversation

@marianne013

Copy link
Copy Markdown
Contributor

@fstagni @martynia
Simon had a go at trying to make the pilot write its log file on a rolling basis. I tested it and as far as I can tell it doesn't break anything.
This might be a good stepping stone towards handling the output in the pilot logger.

@marianne013

Copy link
Copy Markdown
Contributor Author

@sfayer Forgot to tag you.

@martynia

Copy link
Copy Markdown
Contributor

I'm getting the full command buffer from the command execution at the moment, but it could be modified, I think. I can flush my buffer on demand as well, not after certain number of lines.

@fstagni fstagni requested a review from martynia May 30, 2022 07:57
@marianne013

Copy link
Copy Markdown
Contributor Author

@sfayer @fstagni Simon and me were debugging some LHCb pilots (as it happens ;-) using 0 CPU yesterday and we could have really done with a rolling log output. Would you consider approving this pull request as an interim measure until the pilot logger is finished ?

@fstagni

fstagni commented Jun 21, 2022

Copy link
Copy Markdown
Contributor

I can, as anyway this is targeting devel branch and so it will go through a hackathon. It's still a draft though.

@marianne013

Copy link
Copy Markdown
Contributor Author

I'll deal with it after my next meeting, but before the end of today.

@marianne013 marianne013 marked this pull request as ready for review June 21, 2022 15:29
@sfayer

sfayer commented Jun 30, 2022

Copy link
Copy Markdown
Member

@marianne013: from testing, we think this patch is also needed:

             sys.stdout.write("\n")                                                                                                                                                                                                                                         
             sys.stdout.flush()                                                                                                                                                                                                                                             
+            sys.stderr.write("\n")                                                                                                                                                                                                                                         
+            sys.stderr.flush()

Regards,
Simon

@marianne013

Copy link
Copy Markdown
Contributor Author

I was kind of hoping it would let me click the "implement suggestion" button, but alas, no

@martynia martynia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code works in"real life" in our test v7r3 installation, however I'm not sure if python 2 is not a limitation in this scenario.

Comment thread Pilot/pilotTools.py Outdated
sys.stderr.write("\n")
sys.stderr.flush()
# Decode full buffer to ascii (to avoid codepoint splitting problems)
outData = outData.decode("ascii", "replace")

@martynia martynia Jul 5, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since outData and all the chunks are strings, outData.decode will not work in Python 3. I added a little unit test in #158, which passes when run in Python2 only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be slightly more precise as in which test is it that fails and what the error is ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need to check #158 out, and then:

python2 -m pytest tests/CI/Test_simplePilotLogger.py

this would pass. If you run the same test with Python 3 it will fail. This is because outData is a string and doesn't have a decode() method in Python 3. You cannot change everything to bytes to satisfy line #428, because writing to stdout/stderr requires strings (add appending chunks to outData requires strings), so outData must be a string.

You can simply run in python 2 and 3 and see what happens:

text="Hello World"
text.decode('acsii','replace')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extended my test to run it for a bunch of strings with different lengths (not pushed yet). It seemed to run fine, but after I repeated the test for a few times (from a command line, as shown above), I got a failure. It was somewhat difficult to see where the strings were different (at 1025 length...). A closer look (text is a random ASCII letter sequence + \n ) \

  • the original string starts with a newline character, the string processed by the program doesn't (it is now 1024 characters long)

So it is missing a leading newline character. Not the end of the world, we can live with it, I can exclude these cases from a test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we with this? We're really keen to get this rolling output in as it's hampering our attempts to debug other problems as we have to wait for the JobAgent to finish to get its log output...

Regards,
Simon

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you live with the fact, that the code does not work with Python 3 ? See my comments above to Daniela's post.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you live with the fact, that the code does not work with Python 3 ? See my comments above to Daniela's post.

no :)

@martynia

martynia commented Aug 9, 2022

Copy link
Copy Markdown
Contributor
              outChunk = stream.read(1024).decode("ascii", "replace")

E AttributeError: 'str' object has no attribute 'decode'

stream.read() returns an str apparently, so the problem persists in Python 3, doesn't it ?

@sfayer

sfayer commented Aug 9, 2022

Copy link
Copy Markdown
Member
              outChunk = stream.read(1024).decode("ascii", "replace")

E AttributeError: 'str' object has no attribute 'decode'

stream.read() returns an str apparently, so the problem persists in Python 3, doesn't it ?

Nah, stream.read() is bytes on py3, str on py2 (which is how the old code works with both)... We're still running into a few minor unicode problems, but we think that should generally fix it.

@marianne013 marianne013 force-pushed the devel branch 2 times, most recently from 4951efb to 5805e0f Compare August 9, 2022 16:18
@sfayer

sfayer commented Aug 9, 2022

Copy link
Copy Markdown
Member

We've re-tested this latest version with both py3 & py2 and it works for both.... Any other comments?

Regards,
Simon

@martynia martynia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with Python 2 and 3. OK.

@sfayer

sfayer commented Aug 23, 2022

Copy link
Copy Markdown
Member

Hi @fstagni,

I think this PR is all ready to go now, do you need anything further from us to get it merged?

Regards,
Simon

@martynia

martynia commented Oct 11, 2022 via email

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants